# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=rime-bopomofo
pkgver=0.0.0.20210131
_commit=c7618f4f5728e1634417e9d02ea50d82b71956ab
pkgrel=1
pkgdesc="Bopomofo input for rime"
arch=('loong64' 'x86_64')
url="https://github.com/rime/rime-bopomofo"
license=('LGPL')
# Rime will regenerate yaml&prism bin, which makes terra-pinyin required on runtime (for translator)
# rime-cangjie is dependency for reverse lookup
depends=('rime-cangjie' 'rime-terra-pinyin')
makedepends=('librime' 'rime-prelude' 'rime-essay')
source=("https://github.com/rime/rime-bopomofo/archive/$_commit/rime-bopomofo-$_commit.tar.gz")
sha512sums=('106a2897ac409b12e5a9aee35bed31e6bd76e4c2cb5caed5d201e03891b316fe42e279c72e5a3b06fe575ea2e897903986fcab9401933b7dfc4d47064be01bce')

prepare() {
  cd $pkgname-$_commit
  # Link essentials
  for _f in $(pacman -Qql rime-prelude rime-essay rime-terra-pinyin | grep -v "/$"); do ln -sf $_f; done
}

build(){
  cd $pkgname-$_commit
  for _s in $(ls *.schema.yaml); do rime_deployer --compile $_s; done
}

package() {
  cd $pkgname-$_commit
  find . -type l -delete
  rm build/terra_pinyin.*
  rm build/*.txt
  install -Dm644 *.yaml -t "$pkgdir"/usr/share/rime-data/
  install -Dm644 build/* -t "$pkgdir"/usr/share/rime-data/build/
}
